import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import { globalIgnores } from 'eslint/config'

export default tseslint.config([
  globalIgnores(['dist']),
  {
    files: ['**/*.{ts,tsx}'],
    extends: [
      js.configs.recommended,
      ...tseslint.configs.recommended, // 包含 TypeScript 推荐规则
      reactHooks.configs['recommended-latest'], // React Hooks 规则
      reactRefresh.configs.vite, // React Refresh Vite 支持
    ],
    languageOptions: {
      ecmaVersion: 2020,
      globals: globals.browser,
      parserOptions: {
        project: ['./tsconfig.app.json'],  // 改为 app 的配置文件
        tsconfigRootDir: import.meta.dirname,
      }
    },
    rules: {
      // 建议关闭原生 eslint 中与 typescript 冲突的规则
      'no-unused-vars': 'off',
      '@typescript-eslint/no-unused-vars': ['warn'],

      // 可选：如果你不使用 require/exports，可禁用该规则
      'prefer-const': ['warn', { destructuring: 'any', ignoreReadBeforeAssign: false }],
    },
  },
])